define(function(require, exports, module) {
	"use strict";
	require("mui");
	require("jquery");
	require("common");

	var abpUse = require("../abp.js");
	var abp = abpUse.abpstart;
	var template = require("template");
	var commonBack = require("commonBack");
	//钉钉返回
	require('http://g.alicdn.com/ilw/ding/0.8.9/scripts/dingtalk.js');
	var dingTalkNav = require('dd_config');
	//a链接跳转
	mui('#allocate-item').on('tap', 'a', function() {
		document.location.href = this.href + "?dd_nav_bgcolor=FFFF943E";
	});

	//调用页面权限控制接口
	var sourceType = abp.sourceType; //获取权限类型接口数据
	var authorityInit = require("operatAuthority"); //调用封装的权限方法
	var authorityData = sessionStorage.getItem('operatAuthorityData'); //获取权限数据
	var authorityIdList = authorityInit.getJurisdictionId(authorityData); //权限一级判断
	var authorityWH_ALLOCATE = authorityInit.getJurisdiction(authorityData, sourceType.WH_ALLOCATE); //库存调拨权限判断

	$(function() {
		function getRightFun() {
			document.location.href = "../../src/newAllotStock/newAllotStockOrder.html?dd_nav_bgcolor=FFFF943E";
		}
		//返回清楚审批中心订单缓存
		//返回清除缓存
		//不在钉钉中返回
		mui("body").on("tap", "header>button", function() {
			commonBack.secondBack();
		});
		//ios
		dingTalkNav.LeftNavBar(commonBack.secondBack);
		//ad
		dingTalkNav.leftAndroid(commonBack.secondBack);

		if(authorityIdList.indexOf(sourceType.INFO_GOODS) === -1) {
			$('.mui-content').addClass('initContentTips');
			$('.mui-content > .tipsConInit').html("您没有权限查看库存调拨记录资料哦!");
			$("ul.pop-tab > li").addClass('mui-disabled');

			//钉钉右边按钮操作
			dingTalkNav.RightNavBar(false, "新增", "default");

		} else {
			if(authorityWH_ALLOCATE.indexOf(2) === -1) {
				$("header > a").remove();
				//钉钉右边按钮操作
				dingTalkNav.RightNavBar(false, "新增", "default");
			} else {
				$("#addOrder").show();
				//钉钉右边按钮操作
				dingTalkNav.RightNavBar(true, "新增", getRightFun);
			}
			if(authorityWH_ALLOCATE.indexOf(1) === -1) {
				$('.mui-content > .tipsConInit').html("您没有权限查看库存调拨记录资料哦!");
				$('.mui-content').addClass("initContentTips");
				$("ul.pop-tab > li").addClass('mui-disabled');
			} else {

				var whOut = require("../chioceLibrary/libraryList.js");
				whOut.libraryList("whOutList", "#out-wh-items");
				var whIn = require("../chioceLibrary/libraryList.js");
				whIn.libraryList("whInList", "#in-wh-items");
				//调用日期筛选传值
				require("getSearchDateItem");
				//调用状态筛选值
				require("recordStatusID");
				//引入关闭tabjs
				var chioceTab = require("chioceTab");

				var start = "";
				var end = "";
				var outWhId = 0;
				var inWhId = 0;
				var dataState = true;
				var pageState = 10;
				var optionSource = {};

				var option = {};
				var dataModel = {
					"outWhId": outWhId,
					"inWhId": inWhId,
					"serial": "",
					"companyId": [

					],
					"busUserId": [

					],
					"statusId": [

					],
					"start": start,
					"end": end,
					"orderBy": "SerialDate Desc",
					"pageIndex": 1,
					"pageSize": 20
				};

				var page = require("pageui");
				//初始化列表数据
				page.init({
					id: "allocate-item",
					tempid: "allocateList",
					isCache: false,
					pageSize: 20
				}, {
					swipeBack: true
				}, abp.services.app.whAllocateList.getPage, dataModel).dataLoad();

				//时间选择点击事件
				mui('body').on('tap', '.pop-tab-con1 ul li', function() {
					dataState = true;
					start = $(this).attr('data-stateDate');
					end = $(this).attr('data-endDate');
					dataModel.start = start;
					dataModel.end = end;
					page.dataLoad(dataModel);
				});

				//调出仓选择点击事件
				mui('body').on('tap', '#out-wh-items li', function() {
					dataState = true;
					outWhId = $(this).find("a").attr('data-id');
					dataModel.outWhId = outWhId;
					page.dataLoad(dataModel);
				});
				//调入仓选择点击事件
				mui('body').on('tap', '#in-wh-items li', function() {
					dataState = true;
					inWhId = $(this).find("a").attr('data-id');
					dataModel.inWhId = inWhId;
					page.dataLoad(dataModel);
				});

				//引入tab关闭
				mui("body").on("tap", ".pop-tab-conitem li", function() {
					chioceTab.muiSure();
				});

				mui('body').on('tap', '#allocate-item li', function() {
					var id = $(this).attr('id');
					var stastusId = $(this).children("a").children("div").children("div").children(".statusId").attr("data-statusid");
					sessionStorage.setItem('allocateID', id);
					sessionStorage.setItem('allocateStastusId', stastusId);
				});
			}

		}
	});
});